package com.lzx.adx.report.support.strategy.channel;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpUtil;
import com.lzx.adx.report.annnotions.ProductType;
import com.lzx.adx.report.constant.ProductChannelConstant;
import com.lzx.adx.report.dto.AccountDTO;
import com.lzx.adx.report.dto.ReportDTO;
import com.lzx.adx.report.util.URLEncoderDecoderTool;
import com.lzx.adx.report.util.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
@ProductType(ProductChannelConstant.HYXT)
public class HyxtReportStrategy extends AbstractReport{
    @Override
    public String getReportFinalUrl(ReportDTO reportDTO, AccountDTO accountDTO) {

        Map<String, Object> params = new HashMap<>();
        params.put("androidid",reportDTO.getHash_android_id());
        params.put("clickid",reportDTO.getBizRequestId());
        params.put("imei", StringUtils.trim(reportDTO.getImeiSum()));
        params.put("imei_md5", StringUtils.trim(reportDTO.getImeiSum()));
        params.put("oaid", StringUtils.trim(reportDTO.getOaid()));
        params.put("oaid_md5", StringUtils.trim(reportDTO.getOaidSum()));
        params.put("ip",StringUtils.trim(reportDTO.getIp()));

        String callbackUrl=String.format(accountDTO.getDspCallbackUrl(),reportDTO.getBizRequestId());
        String urlParams= UrlUtil.covertParamsOrderByAsc(params)+"&callback="+ URLEncoderDecoderTool.encodeURL(callbackUrl);

        return  accountDTO.getDspReportUrl() + "&" + urlParams;
    }
}
